import Vue from 'vue'
import Router from 'vue-router'
import { constantRouterMap } from '@/config/router.config'
import constantRoutes from './constantRoutes'
import { Modal } from 'ant-design-vue'

// hack router push callback
const originalPush = Router.prototype.push
Router.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => {
    // console.log(err)
    // if (err.toString().indexOf('Loading chunk') > -1) {
    //   Modal.confirm({
    //     title: '提示',
    //     content: '检测到版本更新，是否进行更新？',
    //     onOk: () => {
    //       window.location.reload()
    //     }
    //   })
    // }
    return err
  })
}
// Router
Vue.use(Router)

export default new Router({
  mode: 'history',
  // mode: 'hash',
  routes: constantRouterMap.concat(constantRoutes),
})
